package com.jh.review.config;

import com.jh.review.service.IHttpservice;
import com.jh.review.service.IReviewService;
import com.jh.review.util.JsonUtil;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description:
 * @author: guoc
 * @createDate: 2020/7/24 15:46
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {

    @Autowired
    IReviewService reviewService;


    //3.添加定时任务
    @Scheduled(cron = "0 0 3 * * ?")
    private void configureTasks() {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        String format1 = format.format(new Date());
        String autoHttpInfo = reviewService.autoHttpService();
        String path="d:/review/log/log."+format1+".log";
        String autoHttpInfos=format2.format(new Date())+"---"+autoHttpInfo+"\r\n";
        JsonUtil.writeLocalStrOne(autoHttpInfos,path);
    }

}
